# Contributor: Orhun Parmaksız <orhunparmaksiz@gmail.com>
# Maintainer: Orhun Parmaksız <orhunparmaksiz@gmail.com>
pkgname=rustypaste
pkgver=0.15.0
pkgrel=0
pkgdesc="Minimal file upload/pastebin service"
url="https://github.com/orhun/rustypaste"
arch="all"
license="MIT"
makedepends="cargo zstd-dev openssl-dev cargo-auditable"
subpackages="$pkgname-doc"
source="$pkgname-$pkgver.tar.gz::https://github.com/orhun/rustypaste/archive/v$pkgver.tar.gz"
options="net"

prepare() {
	default_prepare

	# Rust target triple.
	local target=$(rustc -vV | sed -n 's/host: //p')

	# Build against system-provided libzstd.
	mkdir -p .cargo
	cat >> .cargo/config.toml <<-EOF
		[target.$target]
		zstd = { rustc-link-lib = ["zstd"] }
	EOF

	cargo fetch --target="$CTARGET" --locked
}

build() {
	cargo auditable build --frozen --release --no-default-features --features openssl
}

check() {
	cargo test --frozen -- \
		--test-threads 1 \
		--skip "server::tests::test_upload_remote_file" \
		--skip "paste::tests::test_paste_data"
}

package() {
	install -Dm 755 "target/release/$pkgname" -t "$pkgdir/usr/bin"
	install -Dm 644 config.toml -t "$pkgdir/etc/rustypaste"
	install -Dm 644 README.md -t "$pkgdir/usr/share/doc/$pkgname"
	install -Dm 644 LICENSE -t "$pkgdir/usr/share/licenses/$pkgname"
}

sha512sums="
5cd58e3ee66212b7335528c4dcad4859c5842f7b71659c44cbf125971aa124c3b389d9b3103add5158b064200678c43133e5fdf5b8be7e5e96a7148ab7aba138  rustypaste-0.15.0.tar.gz
"
